package net.zjitc.atest.util.TokenUtil;

import io.jsonwebtoken.*;

public class JwtTokenValidator {

    // 密钥需要与生成Token时使用的密钥一致
    private static final String SECRET_KEY = "knbvklc12389ytginposi0r82onklfnbklmsvcklbh8937t4oi6";

    public static Claims validateToken(String token) {
        try {
            // 解析Token并获取Claims
            return Jwts.parser()
                    .setSigningKey(SECRET_KEY)
                    .parseClaimsJws(token)
                    .getBody();
        } catch (ExpiredJwtException e) {
            System.out.println("JWT token has expired.");
            return null;
        } catch (UnsupportedJwtException e) {
            System.out.println("JWT token is unsupported.");
            return null;
        } catch (MalformedJwtException e) {
            System.out.println("Invalid JWT token format.");
            return null;
        } catch (SignatureException e) {
            System.out.println("Invalid JWT signature.");
            return null;
        } catch (Exception e) {
            System.out.println("Invalid JWT token.");
            return null;
        }
    }
}
